package com.fg.util;

import com.fg.util.UsefulFunctions;

public class ContentParser {
	
	/**
	 * contentType과 fileName을 넣으면 icon이미지를 반환한다. 
	 * @param contentType
	 * @param fileName
	 * @return
	 */
	public static String getIcon(String fileName) throws Exception{
		String host = UsefulFunctions.getPropertiesValue("properties/AmazonAccessInfo.properties", "static_bucket_url");
		String path = host+"/images/icons/file/";
		String ext = getExtension(fileName);
		String type = ext.substring(0, 3);
		
		if(type.equals("doc") || type.equals("ppt") || type.equals("xls") || type.equals("hwp") || type.equals("txt") || type.equals("pdf"))
			return path+type+".png";	
		else
			return path+"file.png";
	}
	
	public static String getExtension(String fileName){
		int mid= fileName.lastIndexOf(".");
		return fileName.substring(mid+1,fileName.length());
	}
	
	public static String getFilePath(int team_seq, int task_seq, String stored_name) throws Exception{
		String host = UsefulFunctions.getPropertiesValue("properties/AmazonAccessInfo.properties", "upload_bucket_url");
		String path = host+"/teams/"+team_seq+"/tasks/"+task_seq+"/"+stored_name;
		
		return path;
	}
	
	public static String getProfilePath(int member_seq, String image_name) throws Exception{
		String host = UsefulFunctions.getPropertiesValue("properties/AmazonAccessInfo.properties", "upload_bucket_url");
		
		String path;
		if(image_name.equals("default_image.png")){
			path = host+"/profileImages/default_image.png";
		}else{
			path = host+"/profileImages/"+member_seq+"/"+image_name;
		}
		
		return path;
	}
}
